package com.panku.gen;

import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.DbType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

public class GeneratorBiz {

	public static void main(String[] args) {
		generateCode();
	}

	public static void generateCode() {
		String packageName = "com.panku";

		boolean serviceNameStartWithI = true;// user -> UserService, 设置成true: user -> IUserService

		generateByTables(serviceNameStartWithI, packageName, "t_tj_total_evalinfo");
	}

	private static void generateByTables(boolean serviceNameStartWithI, String packageName, String... tableNames) {

		GlobalConfig config = new GlobalConfig();

		String dbUrl = "jdbc:mysql://192.168.1.67:3306/ses?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&tinyInt1isBit=false";

		DataSourceConfig dataSourceConfig = new DataSourceConfig();

		dataSourceConfig.setDbType(DbType.MYSQL)

				.setUrl(dbUrl)

				.setUsername("******")

				.setPassword("******")

				.setDriverName("com.mysql.jdbc.Driver");

		StrategyConfig strategyConfig = new StrategyConfig();

		strategyConfig

				.setCapitalMode(true)

				.setEntityLombokModel(false)

				.setDbColumnUnderline(true)

				.setNaming(NamingStrategy.underline_to_camel)
				

				.setInclude(tableNames);// 修改替换成你需要的表名，多个表名传数组

		config.setActiveRecord(false)
		
				.setEnableCache(false)
				

				.setAuthor("jack")

				.setOutputDir("d:\\codeGen\\ses")

				.setFileOverride(true);

		if (!serviceNameStartWithI) {

			config.setServiceName("%sService");

		}

		new AutoGenerator().setGlobalConfig(config)

				.setDataSource(dataSourceConfig)

				.setStrategy(strategyConfig)

				.setPackageInfo(

						new PackageConfig()

								.setParent(packageName)

								// .setController("controller")

								.setEntity("entity")

				).execute();

	}
	
	
	

	private static void generateByTables(String packageName, String... tableNames) {

		generateByTables(true, packageName, tableNames);

	}

}
